<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符串剪切</title>
</head>
<body>

</body>
<script>
    String.prototype.mysubstring=function(beginIndex,endIndex){
        var str=this,
            newArr=[];
        if(!endIndex){
            endIndex=str.length;
        }
        for(var i=beginIndex;i<endIndex;i++){
            newArr.push(str.charAt(i));
        }
        return newArr.join("");
    }

    //test
    console.log("Hello world!".mysubstring(3));
    console.log("Hello world!".mysubstring(3,7));
</script>
</html>